package com.xgry.bpm.api.base.userinforole.service.impl;

import com.xgry.bpm.api.base.userinforole.entity.UserInfoRole;
import com.xgry.bpm.api.base.userinforole.mapper.UserInfoRoleMapper;
import com.xgry.bpm.api.base.userinforole.service.UserInfoRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.apache.http.HttpStatus;

import java.util.List;

/**
* <p>
    * UserInfoRole服务实现类
    * </p>
*
* @author adrian
* @since 2020-07-09
*/
@Service
public class UserInfoRoleServiceImpl extends ServiceImpl<UserInfoRoleMapper, UserInfoRole>implements UserInfoRoleService {

    @Override
    public int deleteById(String id){
        if(StringUtils.isEmpty(id)){
            throw new IllegalArgumentException(String.valueOf(HttpStatus.SC_METHOD_FAILURE));
        }
        return baseMapper.deleteById(id);
    }

    @Override
    public UserInfoRole selectById(String id){
        if(StringUtils.isEmpty(id)){
            throw new IllegalArgumentException(String.valueOf(HttpStatus.SC_METHOD_FAILURE));
        }
        UserInfoRole data=baseMapper.selectById(id);
        return data;
    }

    @Override
    public List<UserInfoRole>selectAll(UserInfoRole record){
        QueryWrapper<UserInfoRole>queryWrapper=new QueryWrapper<>();
        queryWrapper.setEntity(record);
        List<UserInfoRole>list=baseMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public IPage<UserInfoRole>selectPage(IPage<UserInfoRole> page , UserInfoRole record){
        // 查询条件
        QueryWrapper<UserInfoRole>queryWrapper=new QueryWrapper<>();
        queryWrapper.setEntity(record);
        return baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public IPage<UserInfoRole>getPage(IPage<UserInfoRole>page,QueryWrapper<UserInfoRole>queryWrapper){
        return baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public List<UserInfoRole> findByUserInfo(Integer userId) {
        return baseMapper.selectList(new QueryWrapper<UserInfoRole>(){{
            this.eq("userInfoId",userId);
        }});
    }
}